<?php

/**
 * @author wanthings.com chengx nixgnehc@gmail.com
 * Low level access control,general web site can useing
 */
class SiteController extends AdminController
{
    public function actionTestamount()
    {
        $data = WayBill::model()->getAmountByAttr();
        var_dump($data);
    }

    public function actionTestmessage()
    {
        echo '<pre>';
        Message::model()->pushMessage();//消息推送
    }

    public function actionIndex()
    {
        // $mobile = '15882138968';
        // $sms_template_code = 'TEST111';
        // $code = array('code'=>'0000');
        // $extra = array();
        // $result = WxUtil::aliyunSend($mobile,$sms_template_code,$code,$extra);
        // var_dump($result);exit;
        if (Yii::app()->user->getIsGuest()) {
            $this->redirect('/admin/manager/login');
        } else {
            $this->render('index');
        }
    }

    public function actionError()
    {
        $error = Yii::app()->errorHandler->error;
        $this->render('error', compact('error'));
    }

    public function actionTest()
    {
        $user_id = Yii::app()->request->getQuery('user_id');
        $r = User::model()->toRunEnd($user_id);
        var_dump($r);
    }

    public function actionGetnew()
    {
        $filter['min_time'] = Yii::app()->request->getQuery('time', time());
        $filter['order_status'] = Order::ORDER_PAY;
        $filter['pay_status'] = Order::PAY;
        $new_order = Order::model()->countByAttr($filter);
        echo $new_order;
    }

    public function actionFile()
    {
        set_time_limit(0);
        $file = fopen(Yii::app()->getBasePath() . "/.." . '/statics' . "/test.txt", "r");
        $i = 0;
        //输出文本中所有的行，直到文件结束为止。
        while (!feof($file)) {
            $data = '';
            $data = fgets($file);//fgets()函数从文件指针中读取一行
            $i++;
            $result = Test::model()->addByStr($data);
            if ($result) {
                echo 'save success->' . $result . '<br/>';
            } else {
                echo 'save error->line->' . $i . '<br/>';
            }
        }
        fclose($file);
    }
}
